package com.zj.demo01.controller;

import com.zj.demo01.dto.QuestionDTO;
import com.zj.demo01.entity.Question;
import com.zj.demo01.service.Impl.QuestionServiceImpl;
import com.zj.demo01.service.QuestionService;
import com.zj.demo01.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName:QuestionController
 * @author:[开发者名称]
 * @Description:[类的功能描述]
 * @Date:2025/9/4/9:51
 * @Version:1.0
 */
@RestController
public class QuestionController {
    @Autowired
    QuestionService questionService;

    /**
     * 查询问题表所有的数据
     * @return
     */
    @GetMapping("")
    public ResultVO selectAllByQuestions(){
        List<Question> list= questionService.selectAllByQuestions();

        ResultVO resultVO= new ResultVO();
        resultVO.setCode(200);
        resultVO.setData(list);

        return resultVO;
    }
    @PostMapping("")
    public ResultVO addQuestions(QuestionDTO questionDTO){
        ResultVO resultVO= new ResultVO();
        if(questionDTO.getTitle()==null&&questionDTO.getTitle().equals("")){

            resultVO.setCode(400);
            resultVO.setMsg("错误信息 问题不能为空");
            return resultVO;

        }
        questionService.addQuestions(questionDTO);
        resultVO.setCode(200);
        return resultVO;

    }
}
